package com.example.mychat.controller;

import com.example.mychat.model.Friend;
import com.example.mychat.model.FriendMapper;
import com.example.mychat.model.User;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
@Slf4j
@RestController
public class FriendController {

    @Autowired
    private FriendMapper friendMapper;

    @GetMapping("/friendList")
    public List<Friend> getFriendList(HttpServletRequest request){
        HttpSession session = request.getSession(false);
        if(session==null){
            log.info("没有登录");
            return new ArrayList<Friend>();
        }
        User user = (User) session.getAttribute("User");
        if(user==null){
            log.info("没有获取到用户信息");
            return new ArrayList<Friend>();
        }
        List<Friend> friends = friendMapper.selectFriendList(user.getId());
        return friends;

    }
}
